package com.springboot.code.String;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * DESC:
 *
 * @author WangJie
 * @date Created in 2022-12-18 17:58
 */
public class StringUtils {

    // todo:
    public static void main(String[] args) {
        /*long msb = System.currentTimeMillis();
        long lsb = System.currentTimeMillis();
        UUID uuidConstructor = new UUID(msb, lsb);
        System.out.println("UUID : "+uuidConstructor);*/
        /*List<User> userList = new ArrayList();
        userList.add(new User("张1", 12, "男"));
        userList.add(new User("张2", 20, "女"));
        userList.add(new User("张3", 18, "男"));
        userList.add(new User("张4", 24, "女"));
        userList.add(new User("张5", 16, "男"));
        userList.add(new User("张1", 12, "男"));
        // 获取userList的name列表
        List<String> collect4 = userList.stream().map(User::getName).collect(Collectors.toList());
        System.out.println(collect4);
        String t = "1";
        System.out.println(t+1);*/

        /*List<Map<String,String>> list = new ArrayList<>();
        Map<String,String> p1 = new HashMap<>();
        p1.put("name", "wangjie");
        p1.put("age", "24");
        Map<String,String> p2 = new HashMap<>();
        p2.put("name", "wangjie2");
        p2.put("age", "23");
        list.add(p1);
        list.add(p2);
        if(list.stream().anyMatch(map -> {return map.get("name").equals("wangjie") && map.get("age").equals("24");})){
            System.out.println();
        }*/

        /*String t = "12";
        List<String> ts = Arrays.asList(t.split("\\|"));
        System.out.println(ts);*/

        /*List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 20000; i++){
            list.add(i);
        }
        List<List<Integer>> subList = splitList(list,5000);
        for (List<Integer> intList : subList){
            System.out.println(intList.size());
        }*/

        /*String date = "2023-04-01,2023-04-07";
        String dateStart = date.substring(0, 10);
        String dateEnd = date.substring(11, 21);
        System.out.println(dateStart);
        System.out.println(dateEnd);*/

        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(dateFormat.format(date));
    }

    /*String str = "";
    List<String> stringList = Arrays.asList(str.split(","));

        System.out.println(stringList);

    List<String> t1 = new ArrayList<>();
        t1.add("1");
        t1.add("2");
    List<String> t2 = new ArrayList<>();
        t2.add("2");
        t2.add("3");
    List<String> list3 = new ArrayList<>();

        for (String t: t1) {
        if (!t2.contains(t)) {
            list3.add(t);
        }
    }

        for (String t : t2) {
        if (!t1.contains(t)) {
            list3.add(t);
        }
    }System.out.println(list3);*/

    private static <T> List<List<T>> splitList(List<T> list, int pageSize) {
        int listSize = list.size();
        int page = (listSize + (pageSize - 1)) / pageSize;//切割集合总个数
        List<List<T>> listArray = new ArrayList<List<T>>();//存放所有被切割的集合
        for (int i = 0; i < page; i++) {
            List<T> subList = new ArrayList<T>();//每个被切割的集合
            for (int j = 0; j < listSize; j++) {
                int pageIndex = ((j + 1) + (pageSize - 1)) / pageSize;//计算出该元素属于哪个集合
                if (pageIndex == (i + 1)) {//判断集合是否匹配，匹配则将元素添加到切割集合中
                    subList.add(list.get(j));
                }
                if ((j + 1) == ((j + 1) * pageSize)) {//如果页数是1，表示会产生listSize数量的集合，此处循环一次即可，节省代码执行速度
                    break;
                }
            }
            listArray.add(subList);
        }
        return listArray;
    }
}
